package cn.itsource.article.controller;

import cn.itsource.article.domain.Comment;
import cn.itsource.article.service.CommentService;
import cn.itsource.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping
    private AjaxResult comment(@RequestBody Comment comment){
        commentService.selectComment(comment);
        return AjaxResult.ok();
    }

    @PatchMapping("/{articleId}")
    private AjaxResult commentId(@PathVariable("articleId") Long articleId){
        List<Comment> comments = commentService.selectCommentId(articleId);
        return AjaxResult.ok(comments);
    }

    @DeleteMapping("/delete/{id}")
    private AjaxResult deletecommentId(@PathVariable("id") String id){
        commentService.deleteCommentId(id);
        return AjaxResult.ok();
    }
}
